package com.im.controller;

import com.im.service.dto.BusiConstParamVal;
import com.im.service.dto.FileUpload;
import com.im.service.dto.ImplementProject;
import com.im.service.dto.PageQuery;
import com.im.service.dto.Staff;
import com.im.service.dto.StageNode;
import com.im.service.folderManage.smo.IFolderManageOperSMO;
import com.im.service.folderManage.smo.IFolderManageQuerySMO;
import com.im.util.JsonUtil;
import com.im.util.ReturnsUtil;
import com.im.viewmodel.folderManage.*;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@EnableAutoConfiguration
@RequestMapping("/folderManageService")
public class FolderManageService extends BaseController {
	private static final Logger logger = LogManager.getLogger(FolderManageService.class);
	@Autowired
	private IFolderManageQuerySMO folderManageQuerySMO;
	@Autowired
	private IFolderManageOperSMO folderManageOperSMO;

	// /**
	// * 父节点文档查询列表
	// */
	// @RequestMapping(value = "/queryFileInfo", method = RequestMethod.POST)
	// @ResponseBody
	// public Object queryFileInfo(@RequestBody String inJson) {
	// Map<String, Object> result = new HashMap<String, Object>();
	// PageQuery<FolderInfoManageRespVo> page = JsonUtil.jsonToBean(inJson,
	// PageQuery.class);
	// List<FolderInfoManageRespVo> respVoList = new
	// ArrayList<FolderInfoManageRespVo>();
	// ProjectStage pStage = new ProjectStage();
	// String projStageId = JsonUtil.obtainValueFromJsonObject(inJson,
	// "projStageId");
	// String impleProjId = JsonUtil.obtainValueFromJsonObject(inJson,
	// "impleProjId");
	// String planProjId = JsonUtil.obtainValueFromJsonObject(inJson,
	// "planProjId");
	// String planProjClass = JsonUtil.obtainValueFromJsonObject(inJson,
	// "planProjClass");
	// String nodeId = JsonUtil.obtainValueFromJsonObject(inJson, "nodeId");
	// String option = JsonUtil.obtainValueFromJsonObject(inJson, "option");
	// pStage.setProjStageId(projStageId);
	// pStage.setImpleProjId(impleProjId);
	// pStage.setPlanProjId(planProjId);
	// pStage.setPlanProjClass(planProjClass);
	// Map<String, Object> paramMap = new HashMap<String, Object>();
	// paramMap.put("projStage", pStage);
	// List<ProjectStage> projStageList =
	// folderManageQuerySMO.queryImpleProjStageList(paramMap);
	// for (ProjectStage stage : projStageList) {
	// String _parentId = null;
	// Map<String, Object> param = new HashMap<String, Object>();
	// StageNode node = new StageNode();
	// String pId = stage.getProjStageId();
	// node.setProjStageId(pId);
	// node.setParentNodeId(nodeId);
	// param.put("stageNode", node);
	// List<StageNode> stageList =
	// folderManageQuerySMO.queryStageNodeList(param);
	// if (stageList.size() > 0) {
	// for (StageNode sNode : stageList) {
	// FolderInfoManageRespVo folderInfoRespVo = new FolderInfoManageRespVo();
	// folderInfoRespVo.set_parentId(_parentId);
	// folderInfoRespVo.setId(sNode.getNodeId());
	// folderInfoRespVo.setImpleProjId(stage.getImpleProjId());
	// folderInfoRespVo.setImpleProjName(stage.getImpleProjName());
	// folderInfoRespVo.setProjectStage(stage);
	// folderInfoRespVo.setProjStateName(stage.getProjStateName());
	// folderInfoRespVo.setStageNode(sNode);
	// Map<String, Object> docMap = new HashMap<String, Object>();
	// DocInfo doc = new DocInfo();
	// doc.setDocObjId(sNode.getNodeId());
	// doc.setDocSourceType("10");
	// docMap.put("docInfo", doc);
	// DocInfo docInfo = folderManageQuerySMO.queryDocInfoInfo(docMap);
	// if (docInfo != null) {
	// folderInfoRespVo.setDocInfo(docInfo);
	// folderInfoRespVo.setStatusCdName(docInfo.getStatusCdName());
	// if ("borrow".equals(option)) {
	// if (docInfo.getStatusCd().equals(20)) {
	// Map<String, Object> borrowMap = new HashMap<String, Object>();
	// FileBorrow fileBorrowInfo = new FileBorrow();
	// fileBorrowInfo.setDocInfoId(docInfo.getDocInfoId());
	// borrowMap.put("fileBorrowInfo", fileBorrowInfo);
	// FileBorrow fileBorrow =
	// folderManageQuerySMO.queryFileBorrowInfoDetail(borrowMap);
	// folderInfoRespVo.setFileBorrow(fileBorrow);
	// }
	// } else {
	// FileUpload fileUpload = new FileUpload();
	// fileUpload.setUploadObjId(docInfo.getDocInfoId());
	// Map<String, Object> docUploadMap = new HashMap<String, Object>();
	// docUploadMap.put("fileUpload", fileUpload);
	// FileUpload fileUploadInfo =
	// folderManageQuerySMO.queryFileUploadInfo(docUploadMap);
	// if (fileUploadInfo != null) {
	// folderInfoRespVo.setUploadInfo(fileUploadInfo);
	// }
	// }
	// }
	// respVoList.add(folderInfoRespVo);
	// }
	// }
	// }
	// PageInfo pageInfo = new PageInfo(respVoList);
	// page.setRows(respVoList);
	// page.setTotalPages(pageInfo.getPages());
	// page.setTotal(pageInfo.getTotal());
	// return buildAjaxResultMap(page, "success", 0);
	// }

	/**
	 * 子节点文档查询列表
	 */
	// @RequestMapping(value = "/queryNodeInfo", method = RequestMethod.POST)
	// @ResponseBody
	// public Object queryNodeInfo(@RequestBody String inJson) {
	// JSONArray returnList = new JSONArray();
	// String nodeId = JsonUtil.obtainValueFromJsonObject(inJson, "nodeId");
	// String option = JsonUtil.obtainValueFromJsonObject(inJson, "option");
	// Map<String, Object> param = new HashMap<String, Object>();
	// StageNode node = new StageNode();
	// node.setParentNodeId(nodeId);
	// param.put("stageNode", node);
	// List<StageNode> stageList =
	// folderManageQuerySMO.queryStageChildNodeList(param);
	// if (stageList.size() > 0) {
	// for (StageNode sNode : stageList) {
	// JSONObject nodeJson = new JSONObject();
	// Map<String, Object> stageMap = new HashMap<String, Object>();
	// ProjectStage projectStage = new ProjectStage();
	// projectStage.setProjStageId(sNode.getProjStageId());
	// stageMap.put("projStage", projectStage);
	// ProjectStage pStage =
	// folderManageQuerySMO.queryImpleProjStageByProjStageId(stageMap);
	// if (pStage != null) {
	// nodeJson.put("impleProjId", pStage.getImpleProjId());
	// nodeJson.put("impleProjName", pStage.getImpleProjName());
	// nodeJson.put("projectStage", pStage);
	// nodeJson.put("projStateName", pStage.getProjStateName());
	// }
	// nodeJson.put("_parentId", nodeId);
	// nodeJson.put("stageNode", sNode);
	// nodeJson.put("id",sNode.getNodeId());
	// Map<String, Object> docMap = new HashMap<String, Object>();
	// DocInfo doc = new DocInfo();
	// doc.setDocObjId(sNode.getNodeId());
	// doc.setDocSourceType("10");
	// docMap.put("docInfo", doc);
	// DocInfo docInfo = folderManageQuerySMO.queryDocInfoInfo(docMap);
	// if (docInfo != null) {
	// nodeJson.put("docInfo", docInfo);
	// nodeJson.put("statusCdName", docInfo.getStatusCdName());
	// if ("borrow".equals(option)) {
	// if (docInfo.getStatusCd().equals(20)) {
	// Map<String, Object> borrowMap = new HashMap<String, Object>();
	// FileBorrow fileBorrowInfo = new FileBorrow();
	// fileBorrowInfo.setDocInfoId(docInfo.getDocInfoId());
	// borrowMap.put("fileBorrowInfo", fileBorrowInfo);
	// FileBorrow fileBorrow =
	// folderManageQuerySMO.queryFileBorrowInfoDetail(param);
	// nodeJson.put("fileBorrow", fileBorrow);
	// }
	// } else {
	// FileUpload fileUpload = new FileUpload();
	// fileUpload.setUploadObjId(docInfo.getDocInfoId());
	// Map<String, Object> docUploadMap = new HashMap<String, Object>();
	// docUploadMap.put("fileUpload", fileUpload);
	// FileUpload fileUploadInfo =
	// folderManageQuerySMO.queryFileUploadInfo(docUploadMap);
	// if (fileUploadInfo != null) {
	// nodeJson.put("uploadInfo", fileUploadInfo);
	// }
	// }
	// }
	// returnList.add(nodeJson);
	// }
	// }
	// return buildAjaxResultMap(returnList, "success", 0);
	// }

	// @RequestMapping(value = "/queryFileInfo", method = RequestMethod.POST)
	// @ResponseBody
	// public Object queryFileInfo(FolderInfoManageReqVo folderInfoManageReqVo)
	// {
	// FolderInfoManageRespVo folderInfoManageRespVo=new
	// FolderInfoManageRespVo();
	// folderInfoManageRespVo.setImpleProjId("1");
	// folderInfoManageRespVo.setImpleProjName("测试");
	//
	// folderInfoManageRespVo.set_parentId(null);
	//
	// folderInfoManageRespVo.setId("1");
	// folderInfoManageRespVo.setProjStateName("工作节点");
	//
	// FileUpload fileUpload=new FileUpload();
	// fileUpload.setUploadName("文件名");
	// folderInfoManageRespVo.setUploadInfo(fileUpload);
	//
	//
	//
	// FolderInfoManageRespVo folderInfoManageRespVo1=new
	// FolderInfoManageRespVo();
	//
	// folderInfoManageRespVo1.setId("1");
	// folderInfoManageRespVo1.setProjStateName("工作节点1");
	// folderInfoManageRespVo1.set_parentId("1");
	//
	// FileUpload fileUpload1=new FileUpload();
	// fileUpload1.setUploadName("文件名1");
	// folderInfoManageRespVo1.setUploadInfo(fileUpload1);
	// folderInfoManageRespVo1.setState("open");
	//
	//
	// FolderInfoManageRespVo folderInfoManageRespVo2=new
	// FolderInfoManageRespVo();
	//
	// folderInfoManageRespVo2.setId("2");
	// folderInfoManageRespVo2.setProjStateName("工作节点2");
	// folderInfoManageRespVo2.set_parentId("1");
	//
	// FileUpload fileUpload2=new FileUpload();
	// fileUpload2.setUploadName("文件名2");
	// folderInfoManageRespVo2.setUploadInfo(fileUpload2);
	// folderInfoManageRespVo2.setState("open");
	//
	//
	// Map<String,Object> result=new HashMap<String,Object>();
	// result.put("total",3);
	// List<FolderInfoManageRespVo> respVoList=new
	// ArrayList<FolderInfoManageRespVo>();
	// respVoList.add(folderInfoManageRespVo);
	// respVoList.add(folderInfoManageRespVo1);
	// respVoList.add(folderInfoManageRespVo2);
	// result.put("rows",respVoList);
	// return buildAjaxResultMap(result,"success",0);
	// }

	@RequestMapping(value = "/test", method = RequestMethod.GET)
	@ResponseBody
	public Object test(String nodeId) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<FolderInfoManageRespVo> respVoList = new ArrayList<FolderInfoManageRespVo>();
		if (StringUtils.isBlank(nodeId)) {
			FolderInfoManageRespVo folderInfoManageRespVo = new FolderInfoManageRespVo();
			folderInfoManageRespVo.setImpleProjId("1");
			folderInfoManageRespVo.setImpleProjName("测试");

			folderInfoManageRespVo.set_parentId(null);

			folderInfoManageRespVo.setId("1");
			folderInfoManageRespVo.setProjStateName("工作节点");

			FileUpload fileUpload = new FileUpload();
			fileUpload.setUploadName("文件名");
			folderInfoManageRespVo.setUploadInfo(fileUpload);

			// FolderInfoManageRespVo folderInfoManageRespVo1=new
			// FolderInfoManageRespVo();
			//
			// folderInfoManageRespVo1.setId("1");
			// folderInfoManageRespVo1.setProjStateName("工作节点1");
			// folderInfoManageRespVo1.set_parentId("1");
			//
			// FileUpload fileUpload1=new FileUpload();
			// fileUpload1.setUploadName("文件名1");
			// folderInfoManageRespVo1.setUploadInfo(fileUpload1);
			// folderInfoManageRespVo1.setState("open");
			//
			//
			// FolderInfoManageRespVo folderInfoManageRespVo2=new
			// FolderInfoManageRespVo();
			//
			// folderInfoManageRespVo2.setId("2");
			// folderInfoManageRespVo2.setProjStateName("工作节点2");
			// folderInfoManageRespVo2.set_parentId("1");
			//
			// FileUpload fileUpload2=new FileUpload();
			// fileUpload2.setUploadName("文件名2");
			// folderInfoManageRespVo2.setUploadInfo(fileUpload2);
			// folderInfoManageRespVo2.setState("open");
			result.put("rows", respVoList);

			respVoList.add(folderInfoManageRespVo);
			// respVoList.add(folderInfoManageRespVo1);
			// respVoList.add(folderInfoManageRespVo2);
		} else {
			FolderInfoManageRespVo folderInfoManageRespVo1 = new FolderInfoManageRespVo();

			folderInfoManageRespVo1.setId("11");
			folderInfoManageRespVo1.setProjStateName("工作节点1");
			folderInfoManageRespVo1.set_parentId("1");

			FileUpload fileUpload1 = new FileUpload();
			fileUpload1.setUploadName("文件名1");
			folderInfoManageRespVo1.setUploadInfo(fileUpload1);
			result.put("rows", respVoList);

			respVoList.add(folderInfoManageRespVo1);

		}

		result.put("total", 1);

		return buildAjaxResultMap(result, "success", 0);
	}

	@RequestMapping(value = "/testuploadimg", method = RequestMethod.POST)
	public @ResponseBody String uploadImg(@RequestParam("myFile") MultipartFile file, HttpServletRequest request) {
		String contentType = file.getContentType();
		String fileName = file.getOriginalFilename();
		System.out.println("fileName-->" + fileName);

		// 上传文件到服务器拿到文件信息后保存到后台
		return null;
	}

	@RequestMapping(value = "/getFile", method = RequestMethod.GET)
	public ResponseEntity<InputStreamResource> downloadFile() throws IOException {
		String filePath = "E:/1.txt";
		FileSystemResource file = new FileSystemResource(filePath);
		HttpHeaders headers = new HttpHeaders();
		headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
		headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getFilename()));
		headers.add("Pragma", "no-cache");
		headers.add("Expires", "0");

		return ResponseEntity.ok().headers(headers).contentLength(file.contentLength())
				.contentType(MediaType.parseMediaType("application/octet-stream"))
				.body(new InputStreamResource(file.getInputStream()));
	}

	/**
	 * 文档详情
	 */
	@RequestMapping(value = "/queryFileInfoDetail", method = RequestMethod.POST)
	@ResponseBody
	public String queryFileInfoDetail(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("查询文档详情请求入参json:{}", inJson);
		}
		try {
			String result = folderManageQuerySMO.queryFileInfoDetail(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("查询文档详情请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("查询文档详情失败！", e).toString();
		}
	}

	/**
	 * 文档新增
	 */
	@RequestMapping(value = "/insertDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public String insertDocInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("staffId", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("新增文档信息请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.insertDocInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("新增文档信息请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("新增文档信息失败！", e).toString();
		}
	}

	/**
	 * 文档修改
	 */
	@RequestMapping(value = "/updateDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public String updateDocInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("staffId", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("修改文档信息请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.updateDocInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("修改文档信息请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("修改文档信息失败！", e).toString();
		}
	}

	/**
	 * 文档批量借阅
	 */
	@RequestMapping(value = "/insertBatchFileBorrowInfo", method = RequestMethod.POST)
	@ResponseBody
	public String insertBatchFileBorrowInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("staffId", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("文档批量借阅请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.insertBatchFileBorrowInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("文档批量借阅请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档批量借阅失败！", e).toString();
		}
	}

	/**
	 * 文档借阅
	 */
	@RequestMapping(value = "/insertFileBorrowInfo", method = RequestMethod.POST)
	@ResponseBody
	public String insertFileBorrowInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("staffId", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("文档借阅请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.insertFileBorrowInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("文档借阅请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档借阅失败！", e).toString();
		}
	}

	/**
	 * 文档批量归还
	 */
	@RequestMapping(value = "/updateBatchFileBorrowInfo", method = RequestMethod.POST)
	@ResponseBody
	public String updateBatchFileBorrowInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("returnBroker", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("文档批量归还请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.updateBatchFileBorrowInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("文档批量归还请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档批量归还失败！", e).toString();
		}
	}

	/**
	 * 文档归还
	 */
	@RequestMapping(value = "/updateFileBorrowInfo", method = RequestMethod.POST)
	@ResponseBody
	public String updateFileBorrowInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("returnBroker", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("文档归还请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.updateFileBorrowInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("文档归还请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档归还失败！", e).toString();
		}
	}

	/**
	 * 增加子节点接口
	 */
	@RequestMapping(value = "/insertChildNodeInfo", method = RequestMethod.POST)
	@ResponseBody
	public String insertNodeInfo(HttpServletRequest request, @RequestBody String inJson) {
		String nodeName = JsonUtil.obtainValueFromJsonObject(inJson, "nodeName");
		String projStageId = JsonUtil.obtainValueFromJsonObject(inJson, "projStageId");
		String parentNodeId = JsonUtil.obtainValueFromJsonObject(inJson, "nodeId");
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String creater = staff.getStaffId();
		// String description = JsonUtil.obtainValueFromJsonObject(inJson,
		// "description");
		String nodeId = UUID.randomUUID().toString();

		StageNode stageNode = new StageNode();
		stageNode.setNodeId(nodeId);
		stageNode.setNodeName(nodeName);
		stageNode.setProjStageId(projStageId);
		stageNode.setNodeLayer("2");
		stageNode.setParentNodeId(parentNodeId);
		stageNode.setStatusCd(10);
		stageNode.setCreater(creater);
		// stageNode.setDescription(description);
		folderManageOperSMO.insertChildNodeInfo(stageNode);

		return ReturnsUtil.returnSuccess(new JSONObject()).toString();
	}

	/**
	 * 项目阶段查询列表
	 */
	@RequestMapping(value = "/queryProjectStageDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public Object queryProjectStageDocInfo(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("查询文档管理项目阶段请求入参json:{}", inJson);
		}
		try {
			PageQuery<FolderInfoManageRespVo> page = folderManageQuerySMO.queryProjectStageDocInfo(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("查询文档管理项目阶段请求出参json:{}", page);
			}
			return ReturnsUtil.returnSuccess(page).toString();
//			return buildAjaxResultMap(page, "success", 0);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("查询文档管理项目阶段失败！", e).toString();
		}
	}

	/**
	 * 根据项目节点id查询文档列表
	 */
	@RequestMapping(value = "/queryDocInfoByProjStageId", method = RequestMethod.POST)
	@ResponseBody
	public Object queryDocInfoByProjStageId(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("查询文档管理项目阶段下文档信息请求入参json:{}", inJson);
		}
		try {
			JSONArray result = folderManageQuerySMO.queryDocInfoByProjStageId(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("查询文档管理项目阶段下文档信息请求出参json:{}", inJson);
			}
			JSONObject respJson = new JSONObject();
			respJson.put("rows", result);
			return ReturnsUtil.returnSuccess(respJson).toString();
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("查询文档管理项目阶段下文档信息失败！", e).toString();
		}
	}

	/**
	 * 文档删除
	 */
	@RequestMapping(value = "/deleteDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public String deleteDocInfo(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("文档删除请求入参json:{}", inJson);
		}
		try {
			String result = folderManageOperSMO.deleteDocInfo(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("文档删除请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档删除失败！", e).toString();
		}
	}

	/**
	 * 文档批量删除
	 */
	@RequestMapping(value = "/deleteDocInfos", method = RequestMethod.POST)
	@ResponseBody
	public String deleteDocInfos(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("文档批量删除请求入参json:{}", inJson);
		}
		try {
			String result = folderManageOperSMO.deleteDocInfos(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("文档批量删除请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档批量删除失败！", e).toString();
		}
	}
	
	/**
	 * 文档上传文件删除
	 */
	@RequestMapping(value = "/delFileUploadByUploadId", method = RequestMethod.POST)
	@ResponseBody
	public String delFileUploadByUploadId(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("文档上传文件删除请求入参json:{}", inJson);
		}
		try {
			String result = folderManageOperSMO.delFileUploadByUploadId(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("文档上传文件删除请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档上传文件批量删除失败！", e).toString();
		}
	}
	
	/**
	 * 查询实施项目列表
	 */
	@RequestMapping(value = "/queryImplementProjectForDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public Object queryImplementProjectForDocInfo(@RequestBody String inJson) {
		if (logger.isInfoEnabled()) {
			logger.info("查询实施项目请求入参json:{}", inJson);
		}
		try {
			PageQuery<ImplementProject> page = folderManageQuerySMO.queryImpleProjListForDocInfo(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("查询实施项目请求出参json:{}", page);
			}
			return ReturnsUtil.returnSuccess(page).toString();
//			return buildAjaxResultMap(page, "success", 0);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("查询实施项目失败！", e).toString();
		}
	}
	
	/**
	 * 项目阶段查询列表
	 */
	@RequestMapping(value = "/queryProjectStageForDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public Object queryProjectStageForDocInfo(@RequestBody String inJson) {
		try {
			List<BusiConstParamVal> page = folderManageQuerySMO.queryProjectStageForDocInfo(inJson);
			if (logger.isInfoEnabled()) {
				logger.info("查询文档管理项目阶段请求出参json:{}", page);
			}
			JSONObject respJson = new JSONObject();
			respJson.put("rows", page);
			return ReturnsUtil.returnSuccess(respJson).toString();
//			return buildAjaxResultMap(page, "success", 0);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("查询文档管理项目阶段失败！", e).toString();
		}
	}
	
	/**
	 * 文档新增(含项目阶段新增)
	 */
	@RequestMapping(value = "/addDocInfo", method = RequestMethod.POST)
	@ResponseBody
	public String addDocInfo(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		param.put("staffId", staffId);
		if (logger.isInfoEnabled()) {
			logger.info("新增文档信息请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.addDocInfo(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("新增文档信息请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("新增文档信息失败！", e).toString();
		}
	}
	
	/**
	 * 文档批量审定
	 */
	@RequestMapping(value = "/updateBatchDcoInfoForAudit", method = RequestMethod.POST)
	@ResponseBody
	public String updateBatchDcoInfoForAudit(HttpServletRequest request, @RequestBody String inJson) {
		JSONObject param = JSONObject.fromObject(inJson);
		HttpSession session = request.getSession();
		Staff staff = (Staff) session.getAttribute("loginedStaff");
		String staffId = staff.getStaffId();
		if (logger.isInfoEnabled()) {
			logger.info("文档批量审定请求入参json:{}", param);
		}
		try {
			String result = folderManageOperSMO.updateBatchDcoInfoForAudit(param.toString());
			if (logger.isInfoEnabled()) {
				logger.info("文档批量审定请求出参json:{}", result);
			}
			return result;
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ReturnsUtil.returnException("文档批量审定失败！", e).toString();
		}
	}

}
